CLI Clipboard
cli-clipboard is a fork of rust-clipboard that adds wayland support for terminal and window-less applications via wl-clipboard-rs. For terminal applications it supports copy and paste for both wayland and X11 linux environments, macOS and windows.
On Linux it will first attempt to setup a Wayland clipboard provider. If that fails it will then fallback to the X11 clipboard provider.
Note: On Linux, you'll need to have xorg-dev and libxcb-composite0-dev to compile. On Debian and Ubuntu you can install them with
sudo apt install xorg-dev libxcb-composite0-dev
Examples
Using ClipboardContext to create a clipboard provider:
use ;
let mut ctx = new.unwrap;
let the_string = "Hello, world!";
ctx.set_contents.unwrap;
assert_eq!;
ctx.clear;
// clearing the clipboard causes get_contents to return Err on macos and windows
if cfg! else
Using the helper functions:
use cli_clipboard;
let the_string = "Hello, world!";
set_contents.unwrap;
assert_eq!;
API
ClipboardProvider
The ClipboardProvider
trait has the following functions:
;
;
;
;
ClipboardContext
ClipboardContext
is a type alias for one of {WindowsClipboardContext
,OSXClipboardContext
,LinuxClipboardContext
}, all of which implementClipboardProvider
. Which concrete type is chosen forClipboardContext
depends on the OS (via conditional compilation).WaylandClipboardContext
andX11ClipboardContext
are also available but generally the correct one will be chosen byLinuxClipboardContext
.
Convenience Functions
get_contents
and set_contents
are convenience functions that create a context for you and call the respective function on it.
Alternatives
- copypasta - rust-clipboard fork adding wayland support for windowed applications
- The original rust-clipboard
License
cli-clipboard
is dual-licensed under MIT and Apache2.